
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Committing code &#8212; Django 1.11.22.dev20190603194737 documentation</title>
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Mailing lists" href="../mailing-lists.html" />
    <link rel="prev" title="Localizing Django" href="localizing.html" />



 
<script type="text/javascript" src="../../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head><body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../../index.html">Django 1.11.22.dev20190603194737 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../../index.html">Home</a>  |
        <a title="Table of contents" href="../../contents.html">Table of contents</a>  |
        <a title="Global index" href="../../genindex.html">Index</a>  |
        <a title="Module index" href="../../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="localizing.html" title="Localizing Django">previous</a>
     |
    <a href="../index.html" title="Django internals" accesskey="U">up</a>
   |
    <a href="../mailing-lists.html" title="Mailing lists">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="internals-contributing-committing-code">
            
  <div class="section" id="s-committing-code">
<span id="committing-code"></span><h1>Committing code<a class="headerlink" href="#committing-code" title="Permalink to this headline">¶</a></h1>
<p>This section is addressed to the committers and to anyone interested in knowing
how code gets committed into Django. If you’re a community member who wants to
contribute code to Django, look at <a class="reference internal" href="writing-code/working-with-git.html"><span class="doc">Working with Git and GitHub</span></a> instead.</p>
<div class="section" id="s-handling-pull-requests">
<span id="s-id1"></span><span id="handling-pull-requests"></span><span id="id1"></span><h2>Handling pull requests<a class="headerlink" href="#handling-pull-requests" title="Permalink to this headline">¶</a></h2>
<p>Since Django is now hosted at GitHub, most patches are provided in the form of
pull requests.</p>
<p>When committing a pull request, make sure each individual commit matches the
commit guidelines described below. Contributors are expected to provide the
best pull requests possible. In practice however, committers - who will likely
be more familiar with the commit guidelines - may decide to bring a commit up
to standard themselves.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Before merging, but after reviewing, have Jenkins test the pull request by
commenting “buildbot, test this please” on the PR.
See our <a class="reference external" href="https://code.djangoproject.com/wiki/Jenkins">Jenkins wiki page</a> for more details.</p>
</div>
<p>An easy way to checkout a pull request locally is to add an alias to your
<code class="docutils literal notranslate"><span class="pre">~/.gitconfig</span></code> (<code class="docutils literal notranslate"><span class="pre">upstream</span></code> is assumed to be <code class="docutils literal notranslate"><span class="pre">django/django</span></code>):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>[alias]
    pr = !sh -c \&quot;git fetch upstream pull/${1}/head:pr/${1} &amp;&amp; git checkout pr/${1}\&quot;
</pre></div>
</div>
<p>Now you can simply run <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">pr</span> <span class="pre">####</span></code> to checkout the corresponding pull
request.</p>
<p>At this point, you can work on the code. Use <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">rebase</span> <span class="pre">-i</span></code> and <code class="docutils literal notranslate"><span class="pre">git</span>
<span class="pre">commit</span> <span class="pre">--amend</span></code> to make sure the commits have the expected level of quality.
Once you’re ready:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> <span class="c1"># Pull in the latest changes from master.</span>
<span class="gp">$</span> git checkout master
<span class="gp">$</span> git pull upstream master
<span class="gp">$</span> <span class="c1"># Rebase the pull request on master.</span>
<span class="gp">$</span> git checkout pr/####
<span class="gp">$</span> git rebase master
<span class="gp">$</span> git checkout master
<span class="gp">$</span> <span class="c1"># Merge the work as &quot;fast-forward&quot; to master to avoid a merge commit.</span>
<span class="gp">$</span> <span class="c1"># (in practice, you can omit &quot;--ff-only&quot; since you just rebased)</span>
<span class="gp">$</span> git merge --ff-only pr/XXXX
<span class="gp">$</span> <span class="c1"># If you&#39;re not sure if you did things correctly, check that only the</span>
<span class="gp">$</span> <span class="c1"># changes you expect will be pushed to upstream.</span>
<span class="gp">$</span> git push --dry-run upstream master
<span class="gp">$</span> <span class="c1"># Push!</span>
<span class="gp">$</span> git push upstream master
<span class="gp">$</span> <span class="c1"># Delete the pull request branch.</span>
<span class="gp">$</span> git branch -d pr/xxxx
</pre></div>
</div>
<p>For changes on your own branches, force push to your fork after rebasing on
master but before merging and pushing to upstream. This allows the commit
hashes on master and your branch to match which automatically closes the pull
request. Since you can’t push to other contributors’ branches, comment on the
pull request “Merged in XXXXXXX” (replacing with the commit hash) after you
merge it. Trac checks for this message format to indicate on the ticket page
whether or not a pull request is merged.</p>
<p>If a pull request doesn’t need to be merged as multiple commits, you can use
GitHub’s “Squash and merge” button on the website. Edit the commit message as
needed to conform to <a class="reference internal" href="#committing-guidelines"><span class="std std-ref">the guidelines</span></a> and remove
the pull request number that’s automatically appended to the message’s first
line.</p>
<p>When rewriting the commit history of a pull request, the goal is to make
Django’s commit history as usable as possible:</p>
<ul class="simple">
<li>If a patch contains back-and-forth commits, then rewrite those into one.
For example, if a commit adds some code and a second commit fixes stylistic
issues introduced in the first commit, those commits should be squashed
before merging.</li>
<li>Separate changes to different commits by logical grouping: if you do a
stylistic cleanup at the same time as you do other changes to a file,
separating the changes into two different commits will make reviewing
history easier.</li>
<li>Beware of merges of upstream branches in the pull requests.</li>
<li>Tests should pass and docs should build after each commit. Neither the
tests nor the docs should emit warnings.</li>
<li>Trivial and small patches usually are best done in one commit. Medium to
large work may be split into multiple commits if it makes sense.</li>
</ul>
<p>Practicality beats purity, so it is up to each committer to decide how much
history mangling to do for a pull request. The main points are engaging the
community, getting work done, and having a usable commit history.</p>
</div>
<div class="section" id="s-committing-guidelines">
<span id="s-id2"></span><span id="committing-guidelines"></span><span id="id2"></span><h2>Committing guidelines<a class="headerlink" href="#committing-guidelines" title="Permalink to this headline">¶</a></h2>
<p>In addition, please follow the following guidelines when committing code to
Django’s Git repository:</p>
<ul>
<li><p class="first">Never change the published history of <code class="docutils literal notranslate"><span class="pre">django/django</span></code> branches by force
pushing. If you absolutely must (for security reasons for example), first
discuss the situation with the team.</p>
</li>
<li><p class="first">For any medium-to-big changes, where “medium-to-big” is according to
your judgment, please bring things up on the <a class="reference internal" href="../mailing-lists.html#django-developers-mailing-list"><span class="std std-ref">django-developers</span></a>
mailing list before making the change.</p>
<p>If you bring something up on <a class="reference internal" href="../mailing-lists.html#django-developers-mailing-list"><span class="std std-ref">django-developers</span></a> and nobody responds,
please don’t take that to mean your idea is great and should be
implemented immediately because nobody contested it. Everyone doesn’t always
have a lot of time to read mailing list discussions immediately, so you may
have to wait a couple of days before getting a response.</p>
</li>
<li><p class="first">Write detailed commit messages in the past tense, not present tense.</p>
<ul class="simple">
<li>Good: “Fixed Unicode bug in RSS API.”</li>
<li>Bad: “Fixes Unicode bug in RSS API.”</li>
<li>Bad: “Fixing Unicode bug in RSS API.”</li>
</ul>
<p>The commit message should be in lines of 72 chars maximum. There should be
a subject line, separated by a blank line and then paragraphs of 72 char
lines. The limits are soft. For the subject line, shorter is better. In the
body of the commit message more detail is better than less:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>Fixed #18307 -- Added git workflow guidelines

Refactored the Django&#39;s documentation to remove mentions of SVN
specific tasks. Added guidelines of how to use Git, GitHub, and
how to use pull request together with Trac instead.
</pre></div>
</div>
<p>If the patch wasn’t a pull request, you should credit the contributors in
the commit message: “Thanks A for report, B for the patch and C for the
review.”</p>
</li>
<li><p class="first">For commits to a branch, prefix the commit message with the branch name.
For example: “[1.4.x] Fixed #xxxxx – Added support for mind reading.”</p>
</li>
<li><p class="first">Limit commits to the most granular change that makes sense. This means,
use frequent small commits rather than infrequent large commits. For
example, if implementing feature X requires a small change to library Y,
first commit the change to library Y, then commit feature X in a separate
commit. This goes a <em>long way</em> in helping everyone follow your changes.</p>
</li>
<li><p class="first">Separate bug fixes from feature changes. Bugfixes may need to be backported
to the stable branch, according to the <a class="reference internal" href="../release-process.html#backwards-compatibility-policy"><span class="std std-ref">backwards-compatibility policy</span></a>.</p>
</li>
<li><p class="first">If your commit closes a ticket in the Django <a class="reference external" href="https://code.djangoproject.com/">ticket tracker</a>, begin
your commit message with the text “Fixed #xxxxx”, where “xxxxx” is the
number of the ticket your commit fixes. Example: “Fixed #123 – Added
whizbang feature.”. We’ve rigged Trac so that any commit message in that
format will automatically close the referenced ticket and post a comment
to it with the full commit message.</p>
<p>If your commit closes a ticket and is in a branch, use the branch name
first, then the “Fixed #xxxxx.” For example:
“[1.4.x] Fixed #123 – Added whizbang feature.”</p>
<p>For the curious, we’re using a <a class="reference external" href="https://github.com/trac-hacks/trac-github">Trac plugin</a> for this.</p>
</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Note that the Trac integration doesn’t know anything about pull requests.
So if you try to close a pull request with the phrase “closes #400” in your
commit message, GitHub will close the pull request, but the Trac plugin
will also close the same numbered ticket in Trac.</p>
</div>
<ul>
<li><p class="first">If your commit references a ticket in the Django <a class="reference external" href="https://code.djangoproject.com/">ticket tracker</a> but
does <em>not</em> close the ticket, include the phrase “Refs #xxxxx”, where “xxxxx”
is the number of the ticket your commit references. This will automatically
post a comment to the appropriate ticket.</p>
</li>
<li><p class="first">Write commit messages for backports using this pattern:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[&lt;Django version&gt;] Fixed &lt;ticket&gt; -- &lt;description&gt;

Backport of &lt;revision&gt; from &lt;branch&gt;.
</pre></div>
</div>
<p>For example:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[1.3.x] Fixed #17028 -- Changed diveintopython.org -&gt; diveintopython.net.

Backport of 80c0cbf1c97047daed2c5b41b296bbc56fe1d7e3 from master.
</pre></div>
</div>
<p>There’s a <a class="reference external" href="https://code.djangoproject.com/wiki/CommitterTips#AutomatingBackports">script on the wiki</a>
to automate this.</p>
</li>
</ul>
</div>
<div class="section" id="s-reverting-commits">
<span id="reverting-commits"></span><h2>Reverting commits<a class="headerlink" href="#reverting-commits" title="Permalink to this headline">¶</a></h2>
<p>Nobody’s perfect; mistakes will be committed.</p>
<p>But try very hard to ensure that mistakes don’t happen. Just because we have a
reversion policy doesn’t relax your responsibility to aim for the highest
quality possible. Really: double-check your work, or have it checked by
another committer, <strong>before</strong> you commit it in the first place!</p>
<p>When a mistaken commit is discovered, please follow these guidelines:</p>
<ul class="simple">
<li>If possible, have the original author revert their own commit.</li>
<li>Don’t revert another author’s changes without permission from the
original author.</li>
<li>Use git revert – this will make a reverse commit, but the original
commit will still be part of the commit history.</li>
<li>If the original author can’t be reached (within a reasonable amount
of time – a day or so) and the problem is severe – crashing bug,
major test failures, etc. – then ask for objections on the
<a class="reference internal" href="../mailing-lists.html#django-developers-mailing-list"><span class="std std-ref">django-developers</span></a> mailing list then revert if there are none.</li>
<li>If the problem is small (a feature commit after feature freeze,
say), wait it out.</li>
<li>If there’s a disagreement between the committer and the
reverter-to-be then try to work it out on the <a class="reference internal" href="../mailing-lists.html#django-developers-mailing-list"><span class="std std-ref">django-developers</span></a>
mailing list. If an agreement can’t be reached then it should
be put to a vote.</li>
<li>If the commit introduced a confirmed, disclosed security
vulnerability then the commit may be reverted immediately without
permission from anyone.</li>
<li>The release branch maintainer may back out commits to the release
branch without permission if the commit breaks the release branch.</li>
<li>If you mistakenly push a topic branch to <code class="docutils literal notranslate"><span class="pre">django/django</span></code>, just delete it.
For instance, if you did: <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">push</span> <span class="pre">upstream</span> <span class="pre">feature_antigravity</span></code>,
just do a reverse push: <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">push</span> <span class="pre">upstream</span> <span class="pre">:feature_antigravity</span></code>.</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Committing code</a><ul>
<li><a class="reference internal" href="#handling-pull-requests">Handling pull requests</a></li>
<li><a class="reference internal" href="#committing-guidelines">Committing guidelines</a></li>
<li><a class="reference internal" href="#reverting-commits">Reverting commits</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="localizing.html"
                        title="previous chapter">Localizing Django</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="../mailing-lists.html"
                        title="next chapter">Mailing lists</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/internals/contributing/committing-code.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Jun 03, 2019</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="localizing.html" title="Localizing Django">previous</a>
     |
    <a href="../index.html" title="Django internals" accesskey="U">up</a>
   |
    <a href="../mailing-lists.html" title="Mailing lists">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>